package copyengine.utils.delayEffect.effect.basic
{
	import copyengine.utils.delayEffect.effect.ICEDelayEffect;

	public class CEDelaySelectableExecuteBranchEffect extends CEDelayContainBranchEffectBasic
	{
		private var totalBranchExecuteFinishNum:int = 0;
		private var totalBranchFlowFinishNum:int = 0;

		public function CEDelaySelectableExecuteBranchEffect()
		{
			super();
		}

		//============================================//
		//==Protected  Function
		//============================================//
		/**
		 * <b>指定Branch内部的Instance来执行</b>
		 */
		protected final function executeSubBranchByInstance(_instance:ICEDelayEffect):void
		{
			for each (var subEffect:ICEDelayEffect in subBranchEffectVector)
			{
				if (subEffect == _instance && !subEffect.isExecuteFinish())
				{
					subEffect.execute(onBranchEffectFlowFinish, onBranchEffectExecuteFinish);
					break;
				}
			}
		}

		private function onBranchEffectFlowFinish():void
		{
			totalBranchFlowFinishNum++;
			totalBranchFlowFinishNum >= subBranchEffectVector.length ? onAllBranchFlowFinish() : null;
		}

		private function onBranchEffectExecuteFinish():void
		{
			totalBranchExecuteFinishNum++;
			totalBranchExecuteFinishNum >= subBranchEffectVector.length ? onAllBranchExecuteFinish() : null;
		}

		//============================================//
		//==OverrideAble  Function
		//============================================//

		protected function onAllBranchExecuteFinish():void
		{
		}

		protected function onAllBranchFlowFinish():void
		{
		}


	}
}
